// @Author YaoYa
// @Date 2024-07-29 22:33:00
// @Desc
package main

import (
	"go.uber.org/zap"
	"time"
)

func NewLogger() (*zap.Logger, error) {
	cfg := zap.NewProductionConfig()
	cfg.OutputPaths = []string{
		"./myproject.log",
		"stderr",
		"stdout",
	}
	return cfg.Build()
}

func main() {
	//logger,_ := zap.NewProduction()
	logger, err := NewLogger()
	if err != nil {
		panic(err)
	}

	sugar := logger.Sugar()
	defer sugar.Sync()
	//sugar := logger.Sugar()
	url := "https://imooc.com"
	sugar.Infow("failed to fetch URL",
		// Structured context as loosely typed key-value pairs.
		"url", url,
		"attempt", 3,
		"backoff", time.Second,
	)
	sugar.Infof("Failed to fetch URL: %s", url)
}
